package com.cssnj.portal.service.query;

import io.predictech.framework.domain.common.JsonRequest;
import io.predictech.framework.domain.common.JsonResponse;
import io.predictech.framework.domain.exception.BaseException;
import io.predictech.framework.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class Query05Service extends BaseService {

    @Qualifier("fifthJdbcTemplate")
    @Autowired
    private JdbcTemplate fifthJdbcTemplate;

    @Override
    protected JsonResponse invokingService(JsonRequest jsonRequest) throws SQLException, BaseException {
        switch (jsonRequest.getHandleCode()) {
            case "queryDataHy":
                return queryDataHy(jsonRequest);
            case "queryDataDq":
                return queryDataDq(jsonRequest);
        }
        return null;
    }

    protected JsonResponse queryDataHy(JsonRequest jsonRequest) {
        JsonResponse jsonResponse = new JsonResponse();
        String swjgdm = (String)jsonRequest.getReqData().get("swjgdm");
        List<Object> params = new ArrayList<Object>();
        params.add(swjgdm);
        List<Map<String, Object>> dataList = queryDao.queryForList(fifthJdbcTemplate,
                 "SELECT HY_DM,HY_MC,CKXS_JE FROM CX_CKMYQK_HY WHERE SWJG_DM = ? ORDER BY XH",params);
        jsonResponse.getRepData().put("dataList", dataList);
        return jsonResponse;
    }

    protected JsonResponse queryDataDq(JsonRequest jsonRequest) {
        JsonResponse jsonResponse = new JsonResponse();
        String swjgdm = (String)jsonRequest.getReqData().get("swjgdm");
        List<Object> params = new ArrayList<Object>();
        params.add(swjgdm);
        List<Map<String, Object>> dataList = queryDao.queryForList(fifthJdbcTemplate,
                "SELECT DQ_DM,DQ_MC,CKXS_JE FROM  CX_CKMYQK_DQ  WHERE SWJG_DM = ? ORDER BY XH",params);
        jsonResponse.getRepData().put("dataList", dataList);
        return jsonResponse;
    }

}
